package cn.darkhorse.alarm.service.impl;

import cn.darkhorse.alarm.mapper.AlarmRecordTimeMapper;
import cn.darkhorse.alarm.pojo.AlarmRecordInfo;
import cn.darkhorse.alarm.pojo.AlarmRecordTime;
import cn.darkhorse.alarm.service.AlarmRecordTimeService;
import cn.darkhorse.common.constant.CommonConstant;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author maoguanjun
 * @since 2023-04-17
 */
@Service
public class AlarmRecordTimeServiceImpl extends ServiceImpl<AlarmRecordTimeMapper, AlarmRecordTime> implements AlarmRecordTimeService {

    /**
     * 查询是否有记录
     *
     * @param recordInfo
     * @return
     */
    @Override
    public Long getCount(AlarmRecordInfo recordInfo) {
        LambdaQueryWrapper<AlarmRecordTime> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(AlarmRecordTime::getAlarmStatus, CommonConstant.NO);
        wrapper.eq(AlarmRecordTime::getDeviceId,recordInfo.getDeviceId());
        wrapper.eq(AlarmRecordTime::getParameterId,recordInfo.getParameterId());
        wrapper.eq(AlarmRecordTime::getAlarmType,recordInfo.getAlarmType());
        wrapper.eq(AlarmRecordTime::getParameterType,recordInfo.getParameterType());
        if(null!=recordInfo.getLimitType()){
            wrapper.eq(AlarmRecordTime::getLimitType,recordInfo.getLimitType());
        }
        if(null!=recordInfo.getChangeType()){
            wrapper.eq(AlarmRecordTime::getChangeType,recordInfo.getChangeType());
        }
        if(null!=recordInfo.getImmediatelyValue()){
            wrapper.eq(AlarmRecordTime::getImmediatelyValue,recordInfo.getImmediatelyValue());
        }
        return count(wrapper);
    }
}
